/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package listeners;

import gui.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import model.DiagramModel;

/**
 *
 * @author Jelle
 */
public class PopupListener extends MouseAdapter {
        Popup popup;
        private DiagramModel model;

        public PopupListener(Popup popup, DiagramModel model) {
            this.popup = popup;
            this.model = model;

            //popup.setLocation(new AbsoluteLocation(50,50));
        }

        public void mousePressed(MouseEvent e) {
            System.out.println("popuplistenermousepressed");
            maybeShowPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            System.out.println("popuplistenermousereleased");
            if(model.isAttachable()){
                System.out.println("popuplistenermousereleased XXXXXXX");
                popup.getPopup().show(e.getComponent(),e.getX(), e.getY());
            }
            else{
            maybeShowPopup(e);
            }
        }

        private void maybeShowPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                popup.getPopup().show(e.getComponent(),
                           e.getX(), e.getY());
              
            }
        }
    }

